﻿// owner 蒋家伟

#include "HashUtils.h"

size_t jsdk::HashUtils::bit_hash(const unsigned char *pSource, size_t count)
{
    //源于std _Hash_seq
#if defined(_WIN64)
    static_assert(sizeof(size_t) == 8, "This code is for 64-bit size_t.");
    constexpr size_t _FNV_offset_basis = 14695981039346656037ULL;
    constexpr size_t _FNV_prime = 1099511628211ULL;

#else /* defined(_WIN64) */
    static_assert(sizeof(size_t) == 4, "This code is for 32-bit size_t.");
    constexpr size_t _FNV_offset_basis = 2166136261U;
    constexpr size_t _FNV_prime = 16777619U;
#endif /* defined(_WIN64) */

    size_t _Val = _FNV_offset_basis;
    for (size_t _Next = 0; _Next < count; ++_Next)
    {	// fold in another byte
        _Val ^= (size_t)pSource[_Next];
        _Val *= _FNV_prime;
    }
    return (_Val); 
}
